;
(function($) {
    window.CurrentLang = 'en'
    window.SupportLang = {
        'en': {
            // pay.html
            phoneLabel: 'Enter the phone number </br>to top-up',
            amountLabel: 'Enter the amount in RUBc',
            pay: 'Pay',
            otherPayMsg: 'You can also top-up your balance in the  <br>following way:',
            schedulePay: 'Schedule automatic payment',
            creditPay: 'Credit card',
            deferredPay: 'Deferred payment',
            //Message page
            SMS: 'SMS',
            New: 'New',
            Read: 'Read',
            Received: 'Received',
            Sent: 'Sent',
            USSD: 'USSD',
            Contactlist: 'Contact list',
            //contacts.html,
            Addcontact: 'Add contact',
            Name: 'Name',
            Phonenumber: 'Phone number',
            Email: 'E-mail',
            Add: 'Add',
            contactTotal: "You have   ",
            contacts: 'contacts',
            device_full: "Contact space on your device is full!",
            //ussd.html
            thecommand: "Enter the command *",
            Keyboard: "Keyboard can be used",
            Reply: "Reply",
            Usefulcommands: "Useful codes",
            balanceCheck: "*100# — balance check",
            checkTheBalance: "*217# — check the balance",
            showMyNumber: "*111*0887# — show my number",
            Replay: "Replay",
            Cancel: "Cancel",
            // ussd.html error message
            UssdErrorInput: "Ussd Error Input",
            Ussdincorrect: 'Warning USSD code is incorrect. Please check the code and try again.',
            ussd_no_service: "No Network Service!",
            ussd_timeout: 'Network Timeout!',
            ussd_retry: 'Operation Failed! Please Retry!',
            ussd_unsupport: 'USSD is unsupported!',
            operation_not_supported: 'operation not supported!',
            network_terminated: 'USSD terminated by network',
            ussd_info_error: 'Get Information Error!',
            ussd_fail: 'Operation Failed!',
            // sms.html
            CreateSMS: 'Create SMS',
            messages: 'messages',
            Youhave: 'You have',
            CreateAmessage: 'Create a message',
            Whom: 'Whom',
            Message: 'Message',
            Send: 'Send',
            send_fail_try_again: 'Send failed.',
            delete_fail_try_again: 'Delete failed, please try again.',
            success_info: "Success",
            error_info: "Failure",
            colon: ":",
            confirmDelete: "Are you sure to delete?",
            sms_capacity_is_full_for_send: "SMS capacity is full, please delete some SMS to receive or send message.",
            sms_capacity_will_full_just: "SMS capacity will be full, you could send {0} SMS(s)",
            draft_capacity_will_full_just: "SMS capacity will be full, you could save {0} SMS(s)",
            // settings_security_filtering
            no_data_selected: "Please select an item!",
            confirm_data_effect: "Your settings may not take effect immediately. If you need to fully take effect, proposed restart the device. Continue?",
            confirm_data_delete: "Are you sure to delete?",
            // settings_system_account
            current_password_error: "Current password is incorrect!",
            // settings_system_power
            wps_wifi_off: "You can''t operate when Wi-Fi is off!",
            wps_on_info: "WPS is enabled now, please try again later.",
            // nosimcard
            last_enter_pin: 'Final attempt. If incorrect again, your SIM card will be locked!',
            pin_error: 'PIN is incorrect!',
            last_enter_puk: 'Final attempt. If incorrect again, your SIM card will be corrupted!',
            puk_error: 'PUK is incorrect!'
        },
        'ru': {
            Settings: 'настройки',
            'JAZZ Network': 'Сеть МТС',
            Menu: 'меню',
            Message: 'Сообщение',
            Payment: 'Оплата',
            Statistic: 'статистика',
            'JAZZ Apps': 'Приложения МТС',
            Password: 'пароль',
            Login: 'Авторизоваться',
            'Only © 2015 JAZZ PJSC shall be shown': 'Только © 2015 ПАО «МТС» будет показано',
            'Please input the password.': 'Пожалуйста, введите пароль.',
            'Unknown error,login failed!': 'Неизвестная ошибка, ошибка входа!',
            'Incorrect password.<br>Please try again.': 'Неверный пароль.<br>Пожалуйста, попробуйте еще раз.',
            'Can not log in!': 'Не можете войти!',
            'Do you want to logout?': 'Вы хотите выйти?',
            'Help': 'Помогите',
            'Logout': 'Выйти'
        },
        'zh-cn': {}
    }

    function getLng(msg) {
        // return window.SupportLang[window.CurrentLang][msg] || msg
        return $.i18n.prop(msg)
    }

    window.LTELanguage_Get = function(msg) {
        return getLng(msg);
    }
    window.LTELanguageChange = function(area) {
        if (window.SupportLang[area]) {
            $.post('goform/goform_set_cmd_process', {
                isTest: false,
                goformId: 'SET_WEB_LANGUAGE',
                Language: area,
                "_": new Date().getTime()
            }, function(data) {
                window.CurrentLang = area;
                //window.LTELanguageInit();
                // 采用i18n
                $.i18n.properties({
                    name: 'Messages',
                    path: 'i18n/',
                    mode: 'map',
                    cache: true,
                    language: area,
                    callback: function() {
                        jQuery.validator.messages = $.i18n.map;
                        $('body').translate();

                        try {
                            _baseLanguageChange(area);
                        } catch (e) {}
                    }
                });
                $("body").removeClass()
                $('body').addClass('lng-' + area)
            });
        }
    }

    window.LTELanguageInit = function() {
        $('[data-lang]').each(function(index, item) {
            if (item.tagName == 'INPUT') {
                $(item).val(getLng($(item).attr('data-lang')));
            } else {
                $(item).html(getLng($(item).attr('data-lang')));
            }
        })
    }

    window.LTELanguageInitPart = function(part) {
        // $(part)
        //     .find('[data-lang]')
        //     .each(function(index, item) {
        //         $(item).html(window.LTELanguage_Get($(item).attr('data-lang')))
        //     })
        $(part).translate();
    }
})(jQuery)